package com.ming.seatMonitoring.controller;


import com.ming.seatMonitoring.pojo.DO.NoticeDO;
import com.ming.seatMonitoring.pojo.DO.UserInfoDO;
import com.ming.seatMonitoring.pojo.entity.ResultBody;
import com.ming.seatMonitoring.service.NoticeService;
import com.ming.seatMonitoring.util.LocalUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


/**
 * @author 小明
 * @date 2021/10/24
 * @description
 */
@RestController
public class NoticeController {

    @Autowired
    NoticeService noticeService;

    @RequestMapping("/getNotice")
    public ResultBody getNotice(){
        return ResultBody.ok().data("notice",noticeService.getNotice());
    }

    @RequestMapping("/updateNotice")
    public ResultBody setNotice(@RequestParam String notice){
        //获取前面公告的id
        final NoticeDO notice1 = noticeService.getNotice();
        //前面的公告伪删除
        notice1.setDeleteTime(new Date());
        noticeService.updateById(notice1);
        //增加新的公告
        final boolean add = noticeService.add(notice);
        if (add){
            return ResultBody.ok().message("更新公告成功");
        }
        return ResultBody.error().message("更新公告失败,请重试");
    }
}
